package park.job;

import java.io.IOException;
import java.util.UUID;
import java.util.logging.Logger;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import net.sf.json.JSONObject;

public class SchedJob implements Job {
	
	private static Logger log =Logger.getLogger(SchedJob.class.getName());

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		// TODO Auto-generated method stub
		ParkInterfaceCollection pc = ParkInterfaceCollection.getInstance();
		HttpPost httppost = new HttpPost("http://192.168.11.146:8000/innerParkMaintenanceService/getParkStatus");
		UUID uuid = UUID.randomUUID();
		httppost.setConfig(pc.getBuild());
		JSONObject jsonParam = new JSONObject();
		jsonParam.put("terminalId", "测试终端");
		jsonParam.put("invokeSerial",uuid);
		StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");// 解决中文乱码问题
		entity.setContentEncoding("UTF-8");
		entity.setContentType("application/json");
		httppost.setEntity(entity);
		System.out.println("Executing request: " + httppost.getRequestLine());
		CloseableHttpResponse response;
		try {
			response = pc.getHttpclient().execute(httppost);
			
			CloseableHttpResponse returnRes = response;
			try {
				System.out.println("----------------------------------------");
				log.info(response.getStatusLine().toString());
				System.out.println(EntityUtils.toString(response.getEntity()));
			} finally {
				response.close();
			}
			
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	

}
